<!-- Sofija Puric 6/08 -->
<?php
include_once dirname(__FILE__) . '/staticStars.php'; 

require 'db.php';
$con=dbConnect("sib");

$letter = $_GET["letter"]; 

//$sql = "SELECT * FROM hostel WHERE strncasecmp (Name, '$letter', 1) = 0";

$sql = "SELECT * FROM hostel WHERE LOCATE('$letter', Name) = 1";

$result = mysql_query($sql, $con);
if (!$result)
      die('Error: ' . mysql_error());

function writeStars($HostelID) {
        $query = "SELECT (avg(Security)+avg(Location)+avg(Service)+avg(Fun)+avg(Cleanliness)+avg(Price))/6 AS prosek " .
                "FROM feedback WHERE IDHostel = $HostelID;";
        $conn = dbConnect("sib");
        $result = mysql_query($query, $conn);
        $row = mysql_fetch_array($result);
        $prosek = $row["prosek"];
        $ss = new staticStars(round($prosek));
        return $ss->printStars($prosek);
    }

if (!isset($result))
        header('Location: ../search_by_letter.php');  // ne zadovoljava nijedan hostel; da li to treba da bude greska ili ne ???
        else {
            while ( $row = mysql_fetch_array($result) ) {
               $idh=$row["IDHostel"];
        $sql_photo = "SELECT * FROM photo WHERE IDHostel = '$idh' AND IndexPhoto = '1'";
        $result_photo = mysql_query($sql_photo, $con);
        if (!$result_photo)
            die('Error: ' . mysql_error());
        $row_photo = mysql_fetch_array($result_photo);
              echo '<div class="hostel">
		<div class="title"><h2>' . $row["Name"] . '</h2></div>
		<a href = "hostel.php?hid=' . $idh . '"><img src="'.$row_photo["Url"].'" alt="'.$row_photo["Alt"].'"/></a>
                    <div class="rate_choice hostels_stars">';
              echo writeStars($idh);
              echo '  </div>
		<div class="entry">' . $row["Description"] . '</div>';
                $idh=$row["IDHostel"];
                echo '
                <div class="links"><a href="hostel.php?hid='.$idh.'">See more</a></div>

	</div>';

            }
        }                           // proveriti da li je unos dobar i sta sve jos treba da se unese !!!!!
                                    // treba uraditi da se unosi odgovaruca slika hostela !!!!!

    mysql_close($con);


/* 
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */

?>
